package br.com.controleFrota;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.telephony.TelephonyManager;
 
public class Preferences extends PreferenceActivity {
 
	public Preference imei;
	public Preference apelido;	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		addPreferencesFromResource(R.layout.preferences);
		setContentView(R.layout.preferences_main);
		
		TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
		
		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

		String apelidoDefault = "Insira seu apelido aqui";
		
		String txApelido = prefs.getString("apelido", apelidoDefault);
		
		if(txApelido.equals(""))
			txApelido = apelidoDefault;
		
		
		apelido = (Preference) findPreference ("apelido");
        imei = (Preference) findPreference ("infoImei");
        
		imei.setSummary(telephonyManager.getDeviceId());
		apelido.setSummary(txApelido);
		
	}
}